package cn.chendd.api.config;

import cn.chendd.api.client.OpenFeignFeaturesClient;
import cn.chendd.logger.OpenFeginLogger;
import com.google.common.collect.Lists;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.util.List;

/**
 * OpenFeignFeaturesClient错误处理工厂
 *
 * @author chendd
 * @date 2023/1/14 21:39
 */
@Component
public class OpenFeignFeaturesClientFallbackFactory implements FallbackFactory<OpenFeignFeaturesClient> {

    @Override
    public OpenFeignFeaturesClient create(Throwable cause) {
        OpenFeginLogger.getLogger().error("调用接口出现错误：" + cause.getMessage() , cause);
        return new OpenFeignFeaturesClient() {
            //实际应用中此处应该是返回统一json数据结构，并且设置状态码为error类
            @Override
            public List<Point> getList() {

                return Lists.newArrayList();
            }

        };
    }
}
